package com.scuec.groupfive.service.impl;

import com.scuec.groupfive.mapper.CorrectStatisticsMapper;
import com.scuec.groupfive.service.CorrectStatisticsService;
import com.scuec.groupfive.vo.CorrectStatisticsVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CorrectStatisticsServiceImpl implements CorrectStatisticsService {

    @Autowired
    private CorrectStatisticsMapper correctStatisticsMapper;

    @Override
    public List<CorrectStatisticsVO> getSubjectCorrectTrend(
            Integer userId,
            String subjectName,
            Integer year,
            Integer startMonth,
            Integer endMonth
    ) {
        // 参数校验
        if (userId == null || subjectName == null || subjectName.isEmpty() || year == null) {
            throw new IllegalArgumentException("用户ID、科目名称和年份为必传参数");
        }

        // 设置默认月份范围
        if (startMonth == null) {
            startMonth = 1;
        }
        if (endMonth == null) {
            endMonth = 12;
        }

        // 月份范围校验
        if (startMonth < 1 || startMonth > 12 || endMonth < 1 || endMonth > 12 || startMonth > endMonth) {
            throw new IllegalArgumentException("月份范围不合法");
        }

        return correctStatisticsMapper.getSubjectCorrectTrend(userId, subjectName, year, startMonth, endMonth);
    }
}